package BNS.graphs;

import java.awt.Point;
import java.io.Serializable;

/** Provides an implementation of a node for our graphs.
	It holds a name (human readable but slow) and an index (fast, machine-convenient)
	as well as an (x,y) where this node should be positioned in the plane.
	It also holds a few other fields (some persistent, some transient).
	*/
public class Node implements Serializable {
	private static final long serialVersionUID = 01L;
	/** the 2-D position of this node on a plane */
    double x,y;
    /** the recent change in the (x,y) position, kept as a sort of momentum feature */
  	transient double dx,dy;
    /** indicates this node is being held in a fixed position */
    boolean fixed;
	/** utility field; used anywhere for algorithmic convenience */
	transient boolean flag;
	/** a label kept in the node, mostly for human consumption */
    public String lbl;
    /** used to indicate position in the state array */
	protected final int index;	
	/** a number controlled by the Graph to count incident edges */
	protected int inDegree, outDegree;
	/** number of edges incident on this node in the supergraph, 
		excluding the ones in the graphlet */
	public int otherEdges;
	/** the neighbouring node chosen by the player of this Node to be his match */
	protected transient Node sweety;
	/** the current color of this Node (See coloring games.) */
	public int color;
	// public transient int color; // TODO: Why is this transient, and is it necessary?
	/** The "class" of the node. Must be a character a-z or A-Z.*/
	public char nodeClass;
	/** The status quo color of the node. Must be an integer. */
	public int sqColor;
	
	/** creates a node with human-readable label, and an int that can be
	used as a machine-readable identifier. It is up to the user to make
	sure that these things are unique. */
	public Node(String lbl, int index, char nodeClass, int sqColor) {
		this.lbl=lbl;
		this.index=index;
		this.nodeClass = nodeClass;
		this.sqColor = sqColor;
		color = sqColor;
		inDegree=0; outDegree=0; otherEdges=0; sweety=null;
	}
	
	/** a constructor that is useful when making graphlets. The label
	and index will be taken from the Node that is being duplicated. */
	public Node(Node that) {
		this(that.lbl, that.index, that.nodeClass, that.sqColor);
		outDegree=that.outDegree; 
		inDegree=that.inDegree;
	}
	
	public String toString() { return lbl; }
	/** adds delta to the current inDegree counter */
	public void addInDegree(int delta) { inDegree+= delta; }
	/** adds delta to the current outDegree counter */
	public void addOutDegree(int delta) { outDegree+= delta; }
	/** returns the total of inDegree and outDegree */
	public int degree() { return inDegree+outDegree; }
	/** returns the location of this node in the state array */
	public int getIndex() { return index; }
	/** returns the current sweety node */
	public Node getSweety() { return sweety; }
	/** changes the current sweety node to s */
	public void setSweety(Node s) { sweety=s; }
	/** obtains the (x,y) layout position of this node */
	public Point position() { return new Point((int)x, (int)y); }
	}
